package ca.compsci.opent.doctool;

/**
 * Models a function in OpenT
 * 
 * @since 0.0.2
 */
public class Function extends Procedure
{
	/**
	 * Return type of this function
	 */
    private Type returnType;
	
    /**
     * Create a new function with identifier, return type and parameters.
	 * 
	 * @param identifier name of this procedure in OpenT code
	 * @param returnType type that this function returns
	 * @param params paramters ot this procedure
	 * 
	 * @since 0.0.2
     */
    public Function(String identifier, Type returnType, Param... params)
    {
		super(identifier, params);
		
		this.returnType = returnType;
    }
	
	/**
	 * Gets this functions return type.
	 * 
	 * @return return type of function in OpenT
	 *
	 * @since 0.0.2
	 */
	public Type getReturnType()
	{
		return returnType;
	}
	
	/**
	 * Returns the string representation of this function.
	 * 
	 * <p>
	 * The representation includes the function's identifier and the list of
	 * its paramaters, followed by its return type:
	 * </p>
	 * 
	 * <p>
	 * {@code function <i>identifier</i> [(<i>param_identifier</i> : <i>type</i>
	 * {, <i>param_identifier</i>} : <i>type</i>)] : <i>returnType</i>}
	 * </p>
	 * 
	 * @return string representation of this function
	 * 
	 * @since 0.0.2
	 */
	@Override
	public String toString()
	{
		return super.toString().replace("procedure", "function") + " : " + returnType;
	}
}
